function initErp() {
    $("input[name=all]").click(function () {
        if (this.checked) {
            $("#tb :checkbox").prop("checked", true);
        } else {
            $("#tb :checkbox").prop("checked", false);
        }
    });

    //终止、生效公告通知
    $('.statusNotice').click(function () {
        var url = $(this).attr('data-url');
        var status = $(this).text();
        $.get(url + '?status=' + status, function (res) {
            console.log(res);
            if (res.status)
                location.reload()
        })
    })

    //查看公告、公文审批意见
    $(document).on('click', '.read_opinion', function () {
        var id = $(this).attr('data-id');
        var table = $(this).attr('data-type');
        var document_w = $(window).width();
        var document_h = $(window).height();
        var layer_w = '550';
        var layer_h = '350';
        var w = (document_w - layer_w) / 2;
        var h = (document_h - layer_h) / 2;
        layer.open({
            type: 2,
            title: [
                "审批意见",
                'background-color: #437dba;color:#fff;text-align:center;font-size:1.4em',
            ],
            area: [layer_w + 'px', layer_h + 'px'], //宽高
            offset: [h + 'px', w + 'px'], //弹出位置 [top,left]
            content: "/index.php/Home/Index/layer/type/9/id/"+id+"/table/"+table
        })
    })

    //终止、生效公文
    $(document).on('click', '.statusDocument', function () {
        var url = $(this).attr('data-url');
        var status = $(this).text();
        $.get(url + '?status=' + status, function (res) {
            console.log(res);
            if (res.status)
                location.reload()
        })
    })

    //审批弹窗（公告通知、公文制度）
    $(document).on('click', '.approve', function () {
        var id = $(this).attr('data-id');
        var table = $(this).attr('data-table');
        var document_w = $(window).width();
        var document_h = $(window).height();
        var layer_w = '550';
        var layer_h = '550';
        var w = (document_w - layer_w) / 2;
        var h = (document_h - layer_h) / 2;
        //不批准需写理由
        layer.open({
            type: 2,
            title: [
                "审批",
                'background-color: #437dba;color:#fff;text-align:center;font-size:1.4em',
            ],
            area: [layer_w + 'px', layer_h + 'px'], //宽高
            offset: [h + 'px', w + 'px'], //弹出位置 [top,left]
            content: "/index.php/Home/Index/layer/type/8/id/"+id+"/table/"+table
        })
    })

    //查询
    $('.search').click(function () {
        $('form').submit();
    })

    //单个删除
    $('.delData').click(function () {
        var url = $(this).attr('data-url');
        layer.confirm('确定要进行此操作吗？', {
            closeBtn: 0,
            btn: ['确定', '取消'] //按钮
        }, function () {
            var index = layer.load(2, {shade: false});
            $.get(url, function (res) {
                console.log(res);
                location.reload()
            })
        })
    })

    //批量删除
    $(document).on('click', '.delMore', function () {
        var url = $(this).attr('data-url');
        var ids = $('.more:checked');
        var param = '';
        if (ids.length == 0) {
            layer.msg('请至少选择一条记录');
            return;
        }
        if (ids.length > 0) {
            var str = new Array();
            ids.each(function () {
                str.push($(this).val());
            });
            param = str.join(',');
        }
        layer.confirm('确定要进行此操作吗？', {
            closeBtn: 0,
            btn: ['确定', '取消'] //按钮
        }, function () {
            var index = layer.load(2, {shade: false});
            $.get(url, {ids: param}, function (res) {
                console.log(res)
                if (res.status) {
                    layer.msg(res.info, {icon: 6});
                    setTimeout(function () {
                        location.reload();
                    }, 1000);
                } else {
                    layer.msg(res.info, {icon: 5});
                    layer.close(index);
                }
            })
        }, function (index) {
            layer.close(index);
        });
    })

    //新建分组
    $('.group').click(function () {
        var document_w = $(window).width();
        var document_h = $(window).height();
        var layer_w = '500';
        var layer_h = '350';
        var w = (document_w - layer_w) / 2;
        var h = (document_h - layer_h) / 2;
        layer.open({
            type: 2,
            title: [
                "新建分组",
                'background-color: #437dba;color:#fff;text-align:center;font-size:1.4em',
            ],
            area: [layer_w + 'px', layer_h + 'px'], //宽高
            offset: [h + 'px', w + 'px'], //弹出位置 [top,left]
            content: "/index.php/Home/Index/layer/type/17"
        })
    })

}

function initSave() {
    //选择人员
    $(document).on('click', '.addUser', function () {
        var id = $(this).attr('data-id');
        var key = $(this).attr('data-key');
        var document_w = $(window).width();
        var document_h = $(window).height();
        var layer_w = '550';
        var layer_h = '550';
        var w = (document_w - layer_w) / 2;
        var h = (document_h - layer_h) / 2;
        layer.open({
            type: 2,
            title: [
                "选择人员",
                'background-color: #437dba;color:#fff;text-align:center;font-size:1.4em',
            ],
            area: [layer_w + 'px', layer_h + 'px'], //宽高
            offset: [h + 'px', w + 'px'], //弹出位置 [top,left]
            content: "/index.php/Home/Index/layer/type/1/id/" + id + "/key/" + key
        })
    })
    //选择角色
    $(document).on('click', '.addPriv', function () {
        var id = $(this).attr('data-id');
        var document_w = $(window).width();
        var document_h = $(window).height();
        var layer_w = '600';
        var layer_h = '550';
        var w = (document_w - layer_w) / 2;
        var h = (document_h - layer_h) / 2;
        layer.open({
            type: 2,
            title: [
                "选择角色",
                'background-color: #437dba;color:#fff;text-align:center;font-size:1.4em',
            ],
            area: [layer_w + 'px', layer_h + 'px'], //宽高
            offset: [h + 'px', w + 'px'], //弹出位置 [top,left]
            content: "/index.php/Home/Index/layer/type/7/field/" + id
        })
    })
    //清空人员或部门
    $('.delData').on('click', function () {
        $(this).parent('.value').find('.textarea span:not(:first)').remove();
    })

    //删除单个用户
    $('body').on('click', '.delOperator', function () {
        $(this).parent('span').remove();
    })

    //选择部门
    $(document).on('click', '.addDept', function () {
        var document_w = $(window).width();
        var document_h = $(window).height();
        var layer_w = '300';
        var layer_h = '500';
        var w = (document_w - layer_w) / 2;
        var h = (document_h - layer_h) / 2;
        layer.open({
            type: 2,
            title: [
                "选择部门",
                'background-color: #437dba;color:#fff;text-align:center;font-size:1.4em',
            ],
            area: [layer_w + 'px', layer_h + 'px'], //宽高
            offset: [h + 'px', w + 'px'], //弹出位置 [top,left]
            content: "/index.php/Home/Index/layer/type/3"
        })
    })



    
    //新建分组
    $('.group').click(function(){
        var document_w = $(window).width();
        var document_h = $(window).height();
        var layer_w = '500';
        var layer_h = '350';
        var w = (document_w - layer_w) / 2;
        var h = (document_h - layer_h) / 2;
        layer.open({
            type: 2,
            title: [
                "新建分组",
                'background-color: #437dba;color:#fff;text-align:center;font-size:1.4em',
            ],
            area: [layer_w + 'px', layer_h + 'px'], //宽高
            offset: [h + 'px', w + 'px'], //弹出位置 [top,left]
            content: "/index.php/Home/Index/layer/type/17"
        })
    })
    
    //根据姓名自动匹配信息
    $('.psn_name').blur(function () {
        var psn_name = $(this).val();
        $.get('getUserInfo', {psn_name: psn_name}, function (res) {
            if (res) {
                $('.mobil_no').val(res.mobil_no);
                $('.email').val(res.email);
                $('.sex').val(res.sex);
            }

        })
    })

}